home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5905 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  48 lines

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Virtual Function in private part?
  5. Date: 7 Feb 1996 12:14:16 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4fa52o$pkb@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe10.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 06, 1996 10:29:52 in article <Virtual Function in private part?>,
  15. 'g9326161@mcmail.cis.McMaster.CA (Hong Shen)' wrote: 
  16.  
  17.  
  18. >Is there any reasons to make a member function in the private section of 
  19. >a class virtual? 
  20. Sure, for example:  
  21.  
  22. class A { public:   
  23. void Expand { Left = MakeChild(); Right = MakeChild(); } 
  24. private: 
  25. virtual A * MakeChild() { return new A; } 
  26. A * Left;  A * Right;  
  27. }; 
  28.  
  29. class B { 
  30.  private: 
  31.   virtual A* MakeChild() { return new B; } 
  32. }; 
  33.  
  34. Now, when you call Expand, the appropriate types of 
  35. objects will be constructed.   
  36.  
  37.  
  38.  
  39. >Thanks. 
  40. >Hong Shen 
  41. -- 
  42. Pete Grant 
  43. Kalevi, Inc. 
  44. Object Oriented Software Development
  45.